import { sendRequest } from '@/http';

const baseUrl = '/admin/staff';

/**
 * 分页查询员工列表
 * @param params
 * @returns
 */
export const queryStaffs = (params: {
  page: number;
  pageSize: number;
  departmentId?: string;
  positionId?: string;
  staffName?: string;
  jobStatus?: string;
}) => {
  return sendRequest({
    url: `${baseUrl}/allStaff`,
    method: 'get',
    params: params as any,
  });
};

/**
 * 创建员工
 * @param data
 * @returns
 */
export const createStaff = (data: {
  staffName: string;
  idCardNo: string;
  phoneNo: string;
  jobStatus: number;
  positionIds: string[];
  departmentIds: string[];
  [x: string]: any;
}) => {
  return sendRequest({
    url: `${baseUrl}/createStaff`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 修改员工
 * @param data
 * @returns
 */
export const updateStaff = (data: {
  staffId?: string;
  staffName: string;
  idCardNo: string;
  phoneNo: string;
  jobStatus: number;
  positionIds: string[];
  departmentIds: string[];
  [x: string]: any;
}) => {
  return sendRequest({
    url: `${baseUrl}/updateStaff`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 获取员工信息
 * @param staffId 员工ID
 * @returns
 */
export const queryStaffInfo = (staffId: string) => {
  return sendRequest({
    url: `${baseUrl}/getStaffInfo`,
    method: 'get',
    params: { staffId },
  });
};

/**
 * 查询员工执行日志
 * @param staffId 员工ID
 * @returns
 */
export const queryStaffExecuteLogs = (params: {
  page: number;
  pageSize: number;
  workDate?: string;
  workTitle?: string;
  elderName?: string;
}) => {
  return sendRequest({
    url: `${baseUrl}/queryStaffExecuteLogs`,
    method: 'get',
    params: params as any,
  });
};

/**
 * 查询员工证书
 * @param staffId 员工ID
 * @returns
 */
export const queryStaffCertificates = (staffId: string) => {
  return sendRequest({
    url: `${baseUrl}/queryStaffCertificates`,
    method: 'get',
    params: { staffId },
  });
};

/**
 * 重置员工密码
 * @param staffId 员工ID
 * @returns
 */
export const resetStaffPassword = (staffId: string) => {
  return sendRequest({
    url: `${baseUrl}/resetStaffPassword`,
    method: 'post',
    data: { staffId },
  });
};

/**
 * 绑定员工手机号
 * @param staffId 员工ID
 * @returns
 */
export const bindStaffPhone = (staffId: string, phoneNo: string) => {
  return sendRequest({
    url: `${baseUrl}/bindStaffPhone`,
    method: 'post',
    data: { staffId, phoneNo },
  });
};

/**
 * 解绑员工手机号
 * @param staffId 员工ID
 * @param smsCode 验证码
 * @returns
 */
export const unBindStaffPhone = (staffId: string, smsCode: string) => {
  return sendRequest({
    url: `${baseUrl}/unBindStaffPhone`,
    method: 'post',
    data: { staffId, smsCode },
  });
};

/**
 * 禁用员工
 * @param staffId 员工ID
 * @returns
 */
export const disableStaff = (staffId: string) => {
  return sendRequest({
    url: `${baseUrl}/disableStaff`,
    method: 'post',
    data: { staffId },
  });
};

/**
 * 启用员工
 * @param staffId 员工ID
 * @returns
 */
export const enableStaff = (staffId: string) => {
  return sendRequest({
    url: `${baseUrl}/enableStaff`,
    method: 'post',
    data: { staffId },
  });
};

/**
 * 获取手机验证码
 * @param phoneNo
 * @returns
 */
export const genSmsCode = (phoneNo: string) => {
  return sendRequest({
    url: `${baseUrl}/genLoginSmsToken`,
    method: 'post',
    data: { phoneNo },
  });
};

/**
 * 获取证书上传令牌
 * @param data
 * @returns
 */
export const genCertificateUploadToken = (data: { localFileName: string }) => {
  return sendRequest({
    url: `${baseUrl}/genCertificateUploadToken`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 上传员工证书 (业务逻辑存在问题)
 * @param data
 * @returns
 */
export const uploadCertificates = (data: {
  staffId: string;
  resIds: number[];
}) => {
  return sendRequest({
    url: `${baseUrl}/uploadCertificates`,
    method: 'post',
    data: data as any,
  });
};
